package com.henanuniversity.test;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Base64;

public class ImageToBase64Converter {
    public static void main(String[] args) {
        String filePath = "D:\\elmpicture\\zhaji.jpg"; // 替换为实际图片路径

        try {
            Path path = Paths.get(filePath);
            byte[] imageData = Files.readAllBytes(path);
            String base64 = Base64.getEncoder().encodeToString(imageData);
            System.out.println(base64);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}